<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="container-div">
	    <div class="col-sm-12 select-info">
			<form id="classList-form">
				<div class="select-list">
					<ul>
						<li>
							名称：<input type="text" name="name"/>
						</li>
						<li>
							年级：<input type="text" name="grade"/>
						</li>
						<li>
							<label class="search-select2-label">现读班级：</label>
							<div class="search-select2-container">
								<select id="nowClass" name="nowClassId">
								</select>
							</div>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-success btn-rounded btn-sm" onclick="$.table.exportExcel()"><i class="fa fa-download"></i>&nbsp;下载</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="resetSearchFrom()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>
		<div class="btn-group hidden-xs" id="toolbar" role="group">
			<a class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add()" shiro:hasPermission="module-student:student:add">
				<i class="fa fa-plus"></i> 新增
			</a>
			<a class="btn btn-outline btn-danger btn-rounded" onclick="$.operate.batRemove()" shiro:hasPermission="module-student:student:remove">
				<i class="fa fa-trash-o"></i> 删除
			</a>
		</div>
			
		<div class="col-sm-12 select-info table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true"></table>
		</div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:src="@{/ajax/libs/select/select2.js}"></script>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('module-student:student:edit')}]];
        var removeFlag = [[${@permission.hasPermi('module-student:student:remove')}]];
        var prefix = ctx + "module/student/student"
        
        function resetSearchFrom(){
     		$.form.reset();
     		$('#nowClass').val(null).trigger("change");
     	}
        
        $(function() {
        	$("#nowClass").select2({
        		ajax: {
			        type:'GET',
			        url: prefix + "/queryClassFormatSelect2",
			        delay: 250,
			        cache: true,
			        processResults: function (data, params) {
			        	data.results.forEach(function(item){
			        		item.id = item.text;
			        	});
			        	return data;
				    }
			    }
        	});
        	
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "学生名单",
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : '编号',
                    visible: false
				},
				{
					field : 'nowClassId', 
					title : '现读班级ID',
					visible: false
				},
				{
					field: 'number',//可不加
					title: '序号',//标题  可不加
					formatter: function (value, row, index) {
						return index+1;
					}
				},
				{
					field : 'name', 
					title : '姓名'
				},
				{
					field : 'sex', 
					title : '性别',
					sortable : true,
					formatter: function(value){
						return value == 0 ? '男' : '女';
					}
				},
				{
					field : 'grade', 
					title : '年级',
					sortable : true
				},
				{
					field : 'telephone', 
					title : '手机号'
				},
				{
					field : 'address', 
					title : '地址'	
				},
				{
					field : 'nowClassName', 
					title : '现读班级'
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>